import {  getUserInfo } from '../../api/login'

Component({
  properties: {
    userID: String,
    ownerID: String,
    ownerInfo: Object,
    isFollowed: Boolean
  },
  data: {
    currentUser: {}
  },
  lifetimes: {
    async attached() {
      const data = {
        from_id: this.properties.userID,
        to_id: this.properties.ownerID
      }
      const res = await getUserInfo(data)
      this.setData({
        currentUser: res
      })
    }
  },
  methods: {
    handleClose() {
      this.triggerEvent('close')
    },
    handleFollow() {
      this.triggerEvent('follow', true)
      this.setData({
        currentUser: {
          ...this.data.currentUser,
          fans: this.data.currentUser.fans + 1
        }
      })
    },
    handleUnfollow() {
      this.triggerEvent('follow', false)
      this.setData({
        currentUser: {
          ...this.data.currentUser,
          fans: this.data.currentUser.fans - 1
        }
      })
    }
  }
})
